﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/SiteMaster.Master"
    Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="Microhard.Framework.MVCHelper" %>
<%@ Import Namespace="Microhard.Permission.Interface" %>
<%@ Import Namespace=" Microhard.Permission.Models" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    组管理
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="section-header">
        <div class="title">
            <img src="<%=Url.Content("~/Content/images/ico-catalog.png")%>" alt="" />
            组管理
        </div>
        <div class="options">
            <table>
                <tr>
                    <td>
                        <%=Html.Authorized_AddButtonWithForm("btnAdd", "添加", "CreateWithParams", "Group", "groupAddForm", null,"admin")%>
                    </td>
                    <td>
                        <%var updateparms = new Dictionary<string, string>();
                          updateparms.Add("identity", "selectedItemID");
                        %>
                        <%=Html.Authorized_UpdateButtonWithForm("btnUpdate", "修改", "Update", "Group", "groupUpdateForm", updateparms,"admin")%>
                    </td>
                    <td>
                        <%=Html.Authorized_DeleteButtonWithCallBack("btnDelete", "删除", "Delete", "Group", "AfterDelete(data);", "passIdentities","Admin")%>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <table width="100%" align="left">
        <tr>
            <td>
                <%= Html.Telerik().TreeView()
                        .Name("orgTreeView")
                        .ClientEvents(events => events
                                                .OnDataBinding("TreeOnDataBinding")
                            .OnSelect("onSelect"))
                %>
            </td>
            <td>
                <table class="adminContent">
                    <tr>
                        <td class="adminTitle">
                            组名称：
                        </td>
                        <td class="adminData">
                            <input type="text" id="groupName" class="text-box single-line" readonly="readonly" />
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            组负责人：
                        </td>
                        <td class="adminData">
                            <input type="text" id="groupManagerMan" class="text-box single-line" readonly="readonly" />
                        </td>
                    </tr>
                    <tr>
                        <td class="adminTitle">
                            备注：
                        </td>
                        <td class="adminData">
                            <input type="text" id="resMark" class="text-box single-line" readonly="readonly" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        var selectedItemID = "";
        var selectedItemTxt = "";
        var passIdentities = [];
        function treeView() {
            return $('#orgTreeView').data('tTreeView');
        }

        function onSelect(e) {
            selectedItemID = treeView().getItemValue(e.item);
            selectedItemTxt = treeView().getItemText(e.item);
            passIdentities[0] = selectedItemID;
            GetInfo(selectedItemID);
        }

        function GetInfo(id) {
            $.getJSON('Group/_GetSingleModel', { id: selectedItemID }, function (data) {
                if (data != null && data != undefined) {
                    $('#groupName').attr('value', data.Name);
                    $('#groupManagerMan').attr('value', data.ManagerManName);
                    $('#resMark').attr('value', data.Description);
                }
                else {
                    alert('获取明细失败');
                }
            });
        }

        function TreeOnDataBinding() {
            var jsonObject = [{ Text: "暂无数据", Expanded: false}];

            var treeview = treeView();
            $.getJSON('Group/_ListWithNoPaging', function (data) {
                if (data.length == 0) {
                    treeview.bindTo(jsonObject);
                    return;
                }
                treeview.bindTo(data);
            });
            treeview.bindTo(jsonObject);
        }

        function AfterDelete(data) {
            if (data == "succeed") {
                TreeOnDataBinding();
                return;
            }
            alert(data);
        }
    </script>
</asp:Content>
